package com.itheima.d3_inner_class3;

public class Test {
    public static void main(String[] args) {
//        Animal a = new Cat();
//        a.cry();


        // 1. 把这个匿名内部类编译成一个子类, 然后会立即创建一个子类对象
        Animal a = new Animal() {
            @Override
            public void cry() {
                System.out.println("这个是一直狗");
            }
        };
        a.cry();

//        Swimming dog = new Swimming() {
//            @Override
//            public void swim() {
//                System.out.println("狗游泳的方法");
//            }
//        };
//
//        Swimming cat = new Swimming() {
//            @Override
//            public void swim() {
//                System.out.println("猫游泳的方法");
//            }
//        };
//        go(dog);
//        go(cat);


        go(new Swimming() {
            @Override
            public void swim() {
                System.out.println("狗游泳的方法");
            }
        });


    }

    public static void go(Swimming s) {
        System.out.println("开始 ========");
        s.swim();
    }
}
